<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>千亿级数据HashMap插入策略</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: linear-gradient(135deg, #1e1e2e 0%, #2d2d44 100%);
            border-radius: 12px;
            overflow: hidden;
        }
        .number-circle {
            width: 48px;
            height: 48px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            font-size: 20px;
        }
        .section-divider {
            height: 2px;
            background: linear-gradient(90deg, transparent, #e5e7eb, transparent);
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="relative overflow-hidden bg-gradient-to-br from-purple-900 via-purple-800 to-indigo-900 text-white">
        <div class="absolute inset-0 bg-black opacity-20"></div>
        <div class="relative container mx-auto px-6 py-24">
            <div class="max-w-4xl mx-auto text-center animate-fadeInUp">
                <h1 class="text-5xl md:text-7xl font-bold mb-6 serif-font">
                    千亿级数据的
                    <span class="block mt-2">HashMap 插入艺术</span>
                </h1>
                <p class="text-xl md:text-2xl text-purple-100 mb-8 leading-relaxed">
                    在没有内存限制的理想世界里，如何将 1000 亿条数据快速、安全地插入到 HashMap 中？
                </p>
                <div class="flex justify-center space-x-8 text-sm">
                    <div class="flex items-center">
                        <i class="fas fa-database mr-2"></i>
                        <span>100,000,000,000 条数据</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-bolt mr-2"></i>
                        <span>极致性能优化</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-shield-alt mr-2"></i>
                        <span>数据安全保障</span>
                    </div>
                </div>
            </div>
        </div>
        <div class="absolute bottom-0 left-0 right-0 h-20 bg-gradient-to-t from-gray-50 to-transparent"></div>
    </section>

    <!-- Introduction -->
    <section class="container mx-auto px-6 py-16">
        <div class="max-w-4xl mx-auto">
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12 card-hover">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="drop-cap serif-font">在</span>大数据时代，处理千亿级别的数据已经成为许多企业面临的现实挑战。HashMap 作为最常用的数据结构之一，在面对如此庞大的数据量时，需要精心设计和优化才能发挥其最佳性能。本文将深入探讨如何通过七大核心策略，实现千亿数据的高效插入。
                </p>
            </div>
        </div>
    </section>

    <!-- Architecture Overview -->
    <section class="container mx-auto px-6 py-16">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-4xl font-bold text-center mb-12 gradient-text">系统架构概览</h2>
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <div class="mermaid">
                    graph TB
                        A[千亿数据源] --> B{数据分片器}
                        B --> C1[分片1<br/>10亿数据]
                        B --> C2[分片2<br/>10亿数据]
                        B --> C3[分片...<br/>10亿数据]
                        B --> C4[分片100<br/>10亿数据]
                        
                        C1 --> D1[线程池1]
                        C2 --> D2[线程池2]
                        C3 --> D3[线程池...]
                        C4 --> D4[线程池100]
                        
                        D1 --> E1[HashMap实例1]
                        D2 --> E2[HashMap实例2]
                        D3 --> E3[HashMap实例...]
                        D4 --> E4[HashMap实例100]
                        
                        E1 --> F[数据聚合层]
                        E2 --> F
                        E3 --> F
                        E4 --> F
                        
                        F --> G[统一访问接口]
                        
                        style A fill:#667eea,stroke:#fff,color:#fff
                        style G fill:#764ba2,stroke:#fff,color:#fff
                </div>
            </div>
        </div>
    </section>

    <!-- Core Strategies -->
    <section class="container mx-auto px-6 py-16">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-4xl font-bold text-center mb-16 gradient-text">七大核心策略</h2>
            
            <!-- Strategy 1 -->
            <div class="mb-12 animate-fadeInUp">
                <div class="flex items-start space-x-6">
                    <div class="number-circle flex-shrink-0">1</div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4 text-gray-800">优化初始容量与负载因子</h3>
                        <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                            <p class="text-gray-700 mb-4">
                                精确计算初始容量是避免频繁扩容的关键。对于千亿级数据，我们需要设置足够大的初始容量，并调整负载因子以最大化内存利用率。
                            </p>
                            <div class="code-block p-4 text-white">
                                <pre><code>// 设置初始容量为1000亿，负载因子为1.0
int initialCapacity = 100_000_000_000;
float loadFactor = 1.0f;
HashMap&lt;Long, String&gt; map = new HashMap&lt;&gt;(initialCapacity, loadFactor);</code></pre>
                            </div>
                            <div class="mt-4 flex items-center text-sm text-purple-600">
                                <i class="fas fa-lightbulb mr-2"></i>
                                <span>提示：负载因子设为1.0可以最大化容量利用，但可能增加哈希冲突</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="section-divider my-8"></div>

            <!-- Strategy 2 -->
            <div class="mb-12 animate-fadeInUp">
                <div class="flex items-start space-x-6">
                    <div class="number-circle flex-shrink-0">2</div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4 text-gray-800">高效哈希函数设计</h3>
                        <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                            <p class="text-gray-700 mb-4">
                                优秀的哈希函数能够将数据均匀分布，减少冲突链表的长度，从而提升查询和插入性能。
                            </p>
                            <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mt-6">
                                <div class="bg-purple-50 rounded-lg p-4 text-center">
                                    <i class="fas fa-random text-3xl text-purple-600 mb-2"></i>
                                    <h4 class="font-semibold">均匀分布</h4>
                                    <p class="text-sm text-gray-600 mt-1">确保哈希值在整个范围内均匀分布</p>
                                </div>
                                <div class="bg-purple-50 rounded-lg p-4 text-center">
                                    <i class="fas fa-tachometer-alt text-3xl text-purple-600 mb-2"></i>
                                    <h4 class="font-semibold">计算高效</h4>
                                    <p class="text-sm text-gray-600 mt-1">哈希函数本身的计算开销要小</p>
                                </div>
                                <div class="bg-purple-50 rounded-lg p-4 text-center">
                                    <i class="fas fa-compress-alt text-3xl text-purple-600 mb-2"></i>
                                    <h4 class="font-semibold">冲突最小化</h4>
                                    <p class="text-sm text-gray-600 mt-1">减少不同键产生相同哈希值的概率</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="section-divider my-8"></div>

            <!-- Strategy 3 -->
            <div class="mb-12 animate-fadeInUp">
                <div class="flex items-start space-x-6">
                    <div class="number-circle flex-shrink-0">3</div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4 text-gray-800">数据分片策略</h3>
                        <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                            <p class="text-gray-700 mb-4">
                                将千亿数据分散到多个HashMap实例中，每个实例处理一部分数据，有效降低单个HashMap的负载。
                            </p>
                            <div class="code-block p-4 text-white mb-4">
                                <pre><code>int shardCount = 100;  // 分为100个分片
HashMap&lt;Long, String&gt;[] shards = new HashMap[shardCount];
for (int i = 0; i &lt; shardCount; i++) {
    shards[i] = new HashMap&lt;&gt;(initialCapacity / shardCount, loadFactor);
}

// 插入时根据key选择分片
long key = ...;
int shardIndex = (int) (key % shardCount);
shards[shardIndex].put(key, value);</code></pre>
                            </div>
                            <div class="bg-gradient-to-r from-purple-100 to-indigo-100 rounded-lg p-4">
                                <h4 class="font-semibold text-purple-800 mb-2">
                                    <i class="fas fa-chart-pie mr-2"></i>分片优势
                                </h4>
                                <ul class="text-sm text-gray-700 space-y-1">
                                    <li>• 降低单个HashMap的内存压力</li>
                                    <li>• 提高并发处理能力</li>
                                    <li>• 便于横向扩展</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="section-divider my-8"></div>

            <!-- Strategy 4 -->
            <div class="mb-12 animate-fadeInUp">
                <div class="flex items-start space-x-6">
                    <div class="number-circle flex-shrink-0">4</div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4 text-gray-800">批量插入优化</h3>
                        <div class="bg-white rounded-xl shadow-lg p-6 card-hover">
                            <p class="text-gray-700 mb-4">
                                批量处理数据可以显著减少操作开销，提高整体插入效率。
                            </p>
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                                <div class="bg-red-50 rounded-lg